<?php
class ChatMessage
{
    public static function createNew($sender, $timeSent, $message)
    {
        $S = new ChatMessage();
        $S->Sender($sender);
        $S->TimeSent($timeSent);
        $S->Message($message);

        return $S;
    }

    public static function createFromArray($values)
    {
        if (!is_array($values)) return null;
        if (count($values) <= 0) return null;

        $S = new ChatMessage();
        $S->FromArray($values);
        return $S;
    }

    public static function createFromCommand(command $cmd)
    {
        logger::called();

        if (!is_array($cmd->Data())) return null;
        if (count($cmd->Data()) <= 0) return null;

        $S = new ChatMessage();
        $S->FromArray($cmd->Data());
        return $S;
    }
    
    public function __construct()
    {

    }

    public function Sender($value = null)
    {
        return $this->GetSetData("Username",null);
    }

    public function TimeSent($value = null)
    {
        return $this->GetSetData("TimeSent",$value);
    }
    
    public function Message($value = null)
    {        
        return $this->GetSetData("MessageContent",$value);
    }

    private $property = array();
    private function GetSetData($property_name,$value = null)
    {
        if (is_null($value) && isset($this->property[$property_name])) return $this->property[$property_name];
        $this->property[$property_name] = $value;
    }

    /*
     * Populate from an array
     */
    public function FromArray($values)
    {
        if (!is_array($values)) return null;

        foreach ($values as $key => $value)
            $this->GetSetData($key,$value);
    }

    public function __toString()
    {
        return print_r($this->property,true);
    }


}

?>
